package com.nanhai.buddhist.college.module.collegebase.dal.mysql.departments;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.datapermission.core.annotation.DataPermission;
import com.nanhai.buddhist.college.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.departments.vo.DepartmentsExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.departments.vo.DepartmentsPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.professions.vo.ProfessionsPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classes.CollegeAndClassesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.colleges.CollegesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.departments.DepartmentsDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.professions.ProfessionsDO;
import org.apache.ibatis.annotations.Mapper;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.departments.vo.*;

/**
 * 学校管理--系部 Mapper
 *
 * @author 开发
 */
@Mapper
public interface DepartmentsMapper extends BaseMapperX<DepartmentsDO> {

    default PageResult<DepartmentsDO> selectPage(DepartmentsPageReqVO reqVO) {
        return selectPageForJoin(reqVO,  DepartmentsDO.class,  new MPJLambdaWrapperX<DepartmentsDO>()
                .likeIfPresent(DepartmentsDO::getDepartmentName, reqVO.getDepartmentName())
                .likeIfPresent(DepartmentsDO::getCode, reqVO.getCode())
                .eqIfPresent(DepartmentsDO::getCollegeId, reqVO.getCollegeId())
                .selectAll(DepartmentsDO.class)
                .selectAs(CollegesDO::getCollegeName,DepartmentsDO::getCollegeName)
                .leftJoin(CollegesDO.class,CollegesDO::getId,DepartmentsDO::getCollegeId)
                .orderByDesc(DepartmentsDO::getCreateTime));
    }

    default List<DepartmentsDO> selectList(DepartmentsExportReqVO reqVO) {
        return selectJoinList(DepartmentsDO.class,new MPJLambdaWrapperX<DepartmentsDO>()
                .likeIfPresent(DepartmentsDO::getDepartmentName, reqVO.getDepartmentName())
                .eqIfPresent(DepartmentsDO::getCode, reqVO.getCode())
                .likeIfPresent(CollegesDO::getCollegeName, reqVO.getCollegeName())
                .selectAll(DepartmentsDO.class)
                .selectAs(CollegesDO::getCollegeName,DepartmentsDO::getCollegeName)
                .leftJoin(CollegesDO.class,CollegesDO::getId,DepartmentsDO::getCollegeId)
                .orderByDesc(DepartmentsDO::getCreateTime));
    }

    @DataPermission(enable = false)
    default List<DepartmentsDO> selectDepartmentsByCollegeIds(Set<String> collegeIds) {
        return selectList(new LambdaQueryWrapper<DepartmentsDO>().in(DepartmentsDO::getCollegeId, collegeIds));
    }
}
